<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	/*******main*******/
	$this->model('member')->checklogin();
	if(intval($_RQ['fromuser'])){
		$this->model('member')->setfromuser();
	}
	$id = intval($_RQ['id']);
	if(!$id){
		exi('该倍财区不存在!','error');
	}
	$this->session('groupid',$id);
	$team=pdo_get('jy_stpinggou_licaigroup',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$team['isnum']=pdo_count('jy_stpinggou_licailog',array('status >='=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$team['id']));
	$team['status1']=pdo_count('jy_stpinggou_licailog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$team['id']));
	//商品多图
	$goods['image']=tomedia($goods['image']);
	//查询该团的所有人
	$pindex = max(1, 0);
	$psize = $team['mannum']+1;
	$members=pdo_getslice('jy_stpinggou_licailog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$team['id']),array($pindex,$psize),$total,array('mid'),'','id asc');
	foreach($members as &$mv){
		$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
		$mv['nickname']=$memberinfo['nickname'];
		$mv['avatar']=$memberinfo['avatar'];
	}
	$return['members']=$members;
	$team['statustitle']='快邀请好友一起来参与倍财吧！';
	$return['team']=$team;
	$return['mylog']=pdo_count('jy_stpinggou_licailog',array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'groupid'=>$team['id']));
	$n=$psize-$team['status1'];
	$lastorder=array();
	for ($i=1; $i<=$n; $i++) {
		$lastlog[]=array('no'=>$i);
	}
	$return['lastlog']=$lastlog?:array();
	$post['num'] = 1;
	$post['groupid']=$team['id'];
	$return['post']=$post;
	$return['xieyi']=$this->plugin_setting('beicaixieyi');
	$return['sharedata']=array(
			'title'=>$nickname.'-发起倍财金收益啦！满'.$team['mannum'].'人就可获利了！',
			'desc'=>'参与倍财金收益啦，满'.$team['mannum'].'人就可获利了！',
			'link'=>custom_url('jy_stpinggou/licai.detail//id='.$team['id'].'&fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>tomedia($team['image'])
	);
	set_html('title',$nickname.'-倍财金');
	exi($return);	
}
// 完成下单
if($_RQ['op']=='post'){
	$post=get_postdata();
	$groupid = $this->session('groupid');
	$status1=pdo_count('jy_stpinggou_licailog',array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'groupid'=>$groupid));
	if($status1){
		exi('该区域的倍财金，您还在参与中！获利出局后，才可以二次参与！','error','jy_stpinggou/licai.log/');
	}
	$status0=pdo_count('jy_stpinggou_licailog',array('status'=>0,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'groupid'=>$groupid));
	if($status0){
		exi('该区域的倍财金，您有一笔订单待支付！','error','jy_stpinggou/licai.log//status=0');
	}
	$group=pdo_get('jy_stpinggou_licaigroup',array('id'=>$groupid));
	$member=pdo_get('jy_stpinggou_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($member['baofee']<$group['fee']){
		exi('您的倍财金不足，不能购买！','error','jy_stpinggou/member.index/');
	}
	$log=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'fee'=>$group['fee'],
		'groupid'=>$group['id'],
		'getfee'=>$group['getfee'],
		'createtime'=>time(),
	);
	$this->pdo_insert('licailog',$log);
	$logid=pdo_insertid();
	$this->model('member')->recharge($_SESSION['uid'],$group['fee'],1,'消费倍财金');
	$update=array(
		'id'=>$logid,
		'status'=>1,
	);
	$this->model('licai')->log_pay($update,$log['groupid']);
	exi('购买成功！','','jy_stpinggou/licai.log//status=0');
}
?>